package org.reborn.model.bound

import org.reborn.math._

/**
 * Base Trait for bounded volumes.
 */
trait Bound {

  /**
   * Determines if this bound intersects with another bound
   * @param bound the other bound to test for intersection
   * @return true if the 2 bounds intersect, false otherwise
   */
  def intersects(bound:Bound):Boolean ={
	BoundIntersection.intersects(this,bound)
  }
  
  /**
   * Determine if this bound completely contains another bound
   * @param bound the other bound to test for containment
   * @return true if this bound completely contains the other bound,
   * false otherwise
   */
  def contains(bound:Bound):Boolean ={
	BoundContains.contains(this,bound)
  }
  
  /**
   * Determine if this bound completely contained inside another bound
   * @param bound the other bound to test for containment
   * @return true if this bound is completely contained by the other bound,
   * false otherwise
   */
  def isContainedBy(bound:Bound):Boolean ={
	bound.contains(this)
  }
  
  /**
   * Determine if a point is inside or touching the edge of this bound
   * @param point the VectorF of length 3 that represents the test point
   * @return true if this bound contains the point, false otherwise
   */
  def containsPoint(point:VectorF):Boolean
}

/**
 * Base trait for Bounding Volumes that can be described by a
 * convex set of planes. 
 */
trait ConvexPlaneBound extends Bound{
  /**
   * The planes that describe the volume contained within the bound.
   * All planes' normals are assumed to face outward away from the 
   * bounding volume.
   */
  val planes:Seq[Plane3F]

  /**
   * Collection of edges that make up the outside of the bound.
   * These edges represent the line segments where the bound's planes
   * intersect.
   */
  val edges:Seq[Line3F]
  
  def containsPoint(point:VectorF):Boolean = {
	planes.forall{_.dist(point) <= 0}  
  }
}

/**
 * Base trait for Bounding Volumes that can be described by a
 * convex, closed set of polygons. 
 */
trait ClosedPolygonalBound extends ConvexPlaneBound{
  
  /**
   * Collection of points that make up the outside of the bound.
   * These points represent the intersection of 3 or more of the 
   * bound's planes 
   */
  val points:Seq[VectorF]
  
  /**
   * The AABB representation of this bound that will be used as a first
   * quick test to determine intersection and containment before moving
   * on to more accurate methods.
   */
  val aabb:AxisAlignedBoundingBox
  
}